package com.ryskoo.startup;

import com.github.tobato.fastdfs.FdfsClientConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.*;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.Executor;

/**
 * @author Shawn
 */
@SpringBootApplication
@ComponentScan(value = {"com.ryskoo"})
@EnableJpaRepositories(basePackages = {"com.ryskoo"})
@EnableElasticsearchRepositories(basePackages = {"com.ryskoo"})
@EntityScan(basePackages = {"com.ryskoo"})
@Import(FdfsClientConfig.class)
@ImportResource("classpath:applicationContext-tx.xml")
public class HclVendorApplication {
	public static void main(String[] args) {
		SpringApplication.run(HclVendorApplication.class, args);
	}

	/**
	 * 配置线程池
	 */
	@EnableAsync
	@Configuration
	class TaskPoolConfig {

		@Bean("taskExecutor")
		public Executor taskExecutor() {
			ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
			executor.setPoolSize(20);
			executor.setThreadNamePrefix("taskExecutor-");
			executor.setWaitForTasksToCompleteOnShutdown(true);
			executor.setAwaitTerminationSeconds(60);
			return executor;
		}

	}
}
